from django.conf import settings
from django.db import transaction
from fdfs_client.client import Fdfs_client

from rest_framework import serializers
from rest_framework.response import Response

from goods.models import SPUSpecification, SPU, Brand, GoodsCategory


class SPUSpecificationSerializer(serializers.ModelSerializer):

    brand_id = serializers.IntegerField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    brand=serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SPU
        # fields = '__all__'
        exclude=('category1','category2','category3')
    #     specs = self.context['request'].data.get('specs')
    #     #事务
    #     with transaction.atomic():
    #         save_point = transaction.savepoint()


class  BrandSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields= "__all__"

class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields  = "__all__"

#
# class Cateogry2Serislzer(serializers.ModelSerializer):
#     class Meta:
#         model  = GoodsCategory
#         fields = "__all__"









